#!/usr/bin/env python
#coding:utf-8
import tornado
from tornado.web import HTTPError
import json

class ErrorHandler(tornado.web.RequestHandler):


    #处理页面访问url没有匹配的情况
    @tornado.web.asynchronous
    def get(self, *args, **kwargs):
        self.set_header("Content-Type", "application/json")
        self.write(json.dumps({'code':404,'message':'非法访问'}))
        self.set_status(404)
        self.finish()
        return

    @tornado.web.asynchronous
    def post(self, *args, **kwargs):
        self.set_header("Content-Type", "application/json")
        self.write(json.dumps({'code':404,'message':'非法访问'}))
        self.set_status(404)
        self.finish()
        return


    #处理逻辑过程中出现的相关错误
    @tornado.web.asynchronous
    def write_error(self, status_code=404, **kwargs):
        self.set_header("Content-Type", "application/json")
        self.write(json.dumps({'code':status_code,'message':kwargs['message']}))
        self.set_status(400)
        self.finish()